package DataStuctures.Stack;

import DataStuctures.LinkList.LinkListDummyHead_Delete;

public class LinkListStack<E> implements Stack{

    private LinkListDummyHead_Delete list;

    public LinkListStack() {
        list = new LinkListDummyHead_Delete();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void push(Object o) {
        list.addFirst(o);
    }

    @Override
    public Object pop() {
        return list.removeFirst();
    }

    @Override
    public Object peek() {
        return list.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append("Stack: Top ");
        res.append(list);
        return res.toString();
    }

    public static void main(String[] args) {
        LinkListStack<Integer> stack = new LinkListStack<>();
        for (int i = 0; i < 5; i++) {
            stack.push(i);
            System.out.println(stack);
        }
        stack.pop();
        System.out.println(stack);
    }
}
